package com.sci.web.dao;

import java.util.List;

import com.sci.web.model.genmodel.User;
import com.sci.web.util.StringUtil;

public class UserDao extends User {
	
	
	public static final  UserDao me = new UserDao();
	
	
	
	
	public int insertUser(User user){
		boolean save = user.save();
		return save==true?1:0;
	}
	
	
	public int updateUser(User user){
		boolean save = user.update();
		return save==true?1:0;
	}
	


	
	/**
	* @Title: geetUserById
	* @Description: TODO(这里用一句话描述这个方法的作用)
	* @param @param Id
	* @param @return    参数
	* @return User    返回类型
	* @throws
	*/
	public User geetUserById(String Id){
		return dao.findById(Id);
	}
	
	
	/**
	* @Title: geetUserByNameAndPwd
	* @Description: TODO(这里用一句话描述这个方法的作用)
	* @param @param userName
	* @param @param pwd
	* @param @return    参数
	* @return User    返回类型
	* @throws
	*/
	public User geetUserByNameAndPwd(String userName , String pwd){
		String sql = " select * from " +User.tableName+ " where (user_no = ? or user_phone=? or user_email=?) and user_pwd = ?";
		return dao.findFirst(sql, userName , userName , userName , pwd);
	}
	
	
	public List<User> geetUserByObj(User user){
		String sql = " select * from " +User.tableName+ " where 1=1 ";
		
		if(StringUtil.isNotEmpty(user.getUserNo())){
			sql += " and user_no = '"+user.getUserNo()+"'";
		}
		if(StringUtil.isNotEmpty(user.getUserName())){
			sql += " and user_name = '"+user.getUserName()+"'";
		}
		if(StringUtil.isNotEmpty(user.getUserEmail())){
			sql += " and user_email = '"+user.getUserEmail()+"'";
		}
		return dao.find(sql);
		
	}

}
